package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ShoppingCart
 * @Author zhuzi
 * @Date 2023/10/01
 */
@RequestMapping("/user/shoppingCart")
@RequiredArgsConstructor
@RestController
@Slf4j
public class ShoppingCartController {

    private final ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result<?> addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("Get ShoppingCartDTO: {}", shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     *
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list() {
        return Result.success(shoppingCartService.list());
    }

    /**
     * 清除购物车
     *
     * @return
     */
    @DeleteMapping("/clean")
    public Result<?> deleteShoppingCart() {
        shoppingCartService.deleteShoppingCart();
        return Result.success();
    }

    /**
     * 减少购物车商品数量
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    public Result<?> subShoppingCartNumber(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.subShoppingCartNumber(shoppingCartDTO);
        return Result.success();
    }

}
